package org.example.Tool;

import org.example.Sort.InsertSort;

import java.util.Arrays;
import java.util.Optional;
/**
 * 检查函数
 * */
public class Logar extends Tool{
    public void sort(Optional<Integer> total,Optional<Integer> maxsize,Optional<Integer> maxvalue){
        int tota = total.orElse(500);
        int size = maxsize.orElse(100);
        int value = maxvalue.orElse(100);
        int count = tota;
        Boolean status = true;
        Long start = System.currentTimeMillis();
        while(tota>=0){
           int[] arr = randomarr(size,value);
           int[] arr2 = Arrays.copyOf(arr,arr.length);
           //检查排序正确性
           new InsertSort().insertsort(arr);
           Arrays.sort(arr2);
           if(!Arrays.equals(arr,arr2)){
               status = false;
               break;
           }
           tota--;
            gress(count-tota,count,start);
        }
        System.out.println(status?"\nSuccess":"\nerror");
    }
    public int[] randomarr(int maxsize,int maxvalue){
        int []arr = new int[maxsize-((int) Math.random()*maxsize)];
        for(int i = 0;i<arr.length;i++){
            arr[i] = (int) (Math.random()*maxvalue) - (int) (Math.random()*maxvalue);
        }
        return arr;
    }
}
